package com.xzssmk.leisure.x.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.xzssmk.leisure.x.po.CardType;
import com.xzssmk.leisure.x.service.CardTypeService;
import com.xzssmk.leisure.x.util.DataTables;

@RestController
@RequestMapping("/cardType")
public class CardTypeController {

    // private final static Logger logger = LoggerFactory.getLogger(CardTypeController.class);

    @Autowired
    private CardTypeService cardTypeService;

    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String add(CardType cardType) {
        return JSONObject.toJSONString(cardTypeService.add(cardType));
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String updateRole(@ModelAttribute CardType cardType) {
        return JSONObject.toJSONString(cardTypeService.update(cardType));
    }

    @RequestMapping(value = "/getCardType", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getById(Integer id) {
        return JSONObject.toJSONString(cardTypeService.getById(id));
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public Object delete(@RequestParam("idlist[]") List<Integer> idlist) {
        return JSONObject.toJSONString(cardTypeService.delete(idlist));
    }

    @RequestMapping(value = "/getPageList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String getPageList(HttpServletRequest request) {
        return JSONObject.toJSONString(cardTypeService.getPageList(DataTables.getInstance(request, null)));
    }

    @RequestMapping(value = "/getCardTypeSelectList", method = RequestMethod.POST,
        produces = "application/json; charset=utf-8")
    public String getCardTypeSelectList() {
        return JSONObject.toJSONString(cardTypeService.getCardTypeSelect());
    }

    @RequestMapping(value = "/cardType-list.html")
    public ModelAndView cardType() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("cardType-list");
        return modelAndView;
    }

    @RequestMapping(value = "/cardType-add.html")
    public ModelAndView addCardType() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("cardType-add");
        return modelAndView;
    }
}
